package gold.digger;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC5475 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {

        int cc;
        int bb;
        int aa;


        public int countGoodTriplets(int[] arr, int a, int b, int c) {
            int count = 0;
            if (arr == null || arr.length < 3) return count;

            cc = c;
            aa = a;
            bb = b;
            for (int i = 0; i < arr.length - 2; i++) {
                for (int j = i + 1; j < arr.length - 1; j++) {
                    for (int k = j + 1; k < arr.length; k++) {
                        if (isMatch(arr[i], arr[j], arr[k])) ++count;
                    }
                }
            }

            return count;
        }

        boolean isMatch(int i, int j, int k) {
            return Math.abs(i - j) <= aa && Math.abs(j - k) <= bb && Math.abs(i - k) <= cc;
        }


        int getTripleMax(int a, int b, int c) {
            return Math.max(a, Math.max(b, c));
        }

        int getTripleMiddle(int a, int b, int c) {
            return Math.min(a, Math.max(b, c));
        }

        int getTripleMin(int a, int b, int c) {
            return Math.min(a, Math.min(b, c));
        }


    }

    public void run() {
        Solution solution = new Solution();
        int[] arr = InputUtil.toIntegerArray("[7,3,7,3,12,1,12,2,3]");
        System.out.println(solution.countGoodTriplets(arr, 5, 8, 1));
    }

    public static void main(String[] args) throws Exception {
        LC5475 an = new LC5475();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}

